#include  <iostream>
#include <fstream>
#include <string>
#include "DllTest.h"

using namespace SystemTool;

static void LogFile(std::string strMsg)
{
    std::string strFilePath = "/Users/tangyingzhong/Desktop/12.log";
    std::fstream os(strFilePath,std::ios::app | std::ios::out);
    os << strMsg << "\n";
    os.close();
}

static void TestCopy(std::string strData)
{
    LogFile(strData);
}

void DllTest()
{
    // Normal scene
    std::string strLibPath = "/Users/tangyingzhong/Desktop/MyCode/Stage/BaseTool/build/Debug/libBaseTool.dylib";
    DllLoader Loader(strLibPath);
    if(!Loader.IsLoaded())
    {
        LogFile("Library is not loaded");
        return;
    }
    typedef void(*SayHello)();
    SayHello pFunc = (SayHello)Loader.GetExportFunc("SayHello");
    if (pFunc)
    {
        pFunc();
    }

    // Unexception scene
    Loader.Load(strLibPath);
    if(Loader.IsLoaded())
    {
        std::cout << "Load ok\n";
        void* pInterface = Loader.GetExportFunc("fjdhfjsfhsfs");
        if(pInterface == nullptr)
        {
            std::cout << "Failed to get func!\n";
            Loader.UnLoad();
            return;
        }
        Loader.UnLoad();
    }

    return;
}
